package simulator.entities;

import java.awt.Color;
import java.awt.Graphics;

import simulator.drawengine.DrawEngine;
import simulator.enums.Direction;
import simulator.enums.LightState;
import simulator.types.Vector2f;

public class BikeTrafficLight extends BaseTrafficlight
{
	boolean[] _lights = new boolean[2]; //green, red
	
	
	public BikeTrafficLight()
	{
		setRed();
	}

	@Override
	protected boolean isValidState(LightState state)
	{
		switch(state)
		{
			case GREEN:
			case RED:
			case BLINK_ERR:
			case OFF:
				return true;
			default:
				return false;
		}
	}
	
	@SuppressWarnings("incomplete-switch")
	@Override
	protected void updateLights()
	{
		switch(_state)
		{
			case GREEN:
				setGreen();
				break;
			case BLINK_ERR:
				if(_blinkstate)
					setRed();
				else
					setOff();
				break;
			case RED:
				setRed();
				break;
			case OFF:
				setOff();
				break;
		}
	}
	
	private void setGreen()
	{
		_lights[0] = true;
		_lights[1] = false;
	}
	
	private void setRed()
	{
		_lights[0] = false;
		_lights[1] = true;
	}
	
	private void setOff()
	{
		_lights[0] = false;
		_lights[1] = false;
	}

	@Override
	public void onDraw(Graphics g, Vector2f position, Direction dir)
	{
		// TODO Auto-generated method stub
		
		//_state		status van stoplicht
		//_blinkstate	wanneer stoplicht moet knipperen, geeft deze boolean aan of het betreffende licht momenteel aan of uit is
		
		// -of-
		
		//_lights		boolean-array welke aangeeft welke lichten aan of uit staan
		
		int gfxX = DrawEngine.getGraphicsX(position.x);
		int gfxY = DrawEngine.getGraphicsY(position.y);
		
		switch(_state)
		{
		case GREEN:
			g.setColor(Color.green);
			g.fillOval(gfxX - 6, gfxY - 6, 14, 14);
			g.setColor(Color.black);
			g.drawOval(gfxX - 7, gfxY - 7, 15, 15);
			break;
		case RED:
			g.setColor(Color.red);
			g.fillOval(gfxX - 6, gfxY - 6, 14, 14);
			g.setColor(Color.black);
			g.drawOval(gfxX - 7, gfxY - 7, 15, 15);
			break;
		case ORANGE:
			g.setColor(Color.orange);
			g.fillOval(gfxX - 6, gfxY - 6, 14, 14);
			g.setColor(Color.black);
			g.drawOval(gfxX - 7, gfxY - 7, 15, 15);
			break;
		case OFF:
			g.setColor(Color.gray);
			g.fillOval(gfxX - 6, gfxY - 6, 14, 14);
			g.setColor(Color.black);
			g.drawOval(gfxX - 7, gfxY - 7, 15, 15);
			break;
		case BLINK:
			if (_blinkstate)
				g.setColor(Color.orange);
			else
				g.setColor(Color.gray);
			g.fillOval(gfxX - 6, gfxY - 6, 14, 14);
			g.setColor(Color.black);
			g.drawOval(gfxX - 7, gfxY - 7, 15, 15);
			break;
		}
	}
}
